using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutomaticSubtitles.Service.DataAccess;
using AutomaticSubtitles.Service.DataAccess.Model;
using AutomaticSubtitles.Service.Domain.Filter;
using AutomaticSubtitles.Service.Infrastructure.Repositories.Base;
using Masa.BuildingBlocks.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;

namespace AutomaticSubtitles.Service.Infrastructure.Repositories;

/// <summary>
/// 词语过滤仓储实现
/// </summary>
public class FilterWordsRepository(AutoDbContext context, IUnitOfWork unitOfWork, IStringLocalizer<SharedResource> localizer) :
    BaseRepository<AutoDbContext, Auto_FilterWords, string>(context, unitOfWork, localizer), IFilterWordsRepository
{
    /// <summary>
    /// 获取所有启用的过滤词
    /// </summary>
    /// <returns>过滤词列表</returns>
    public async Task<List<string>> GetActiveFilterWordsAsync()
    {
        return await Context.Set<Auto_FilterWords>()
            .Where(w => w.IsActive)
            .Select(w => w.Word)
            .ToListAsync();
    }

    /// <summary>
    /// 获取特定语言的过滤词
    /// </summary>
    /// <param name="language">语言代码</param>
    /// <returns>特定语言的过滤词列表</returns>
    public async Task<List<string>> GetActiveLanguageFilterWordsAsync(string language)
    {
        return await Context.Set<Auto_LanguageFilterWords>()
            .Where(w => w.IsActive && w.Language == language)
            .Select(w => w.Word)
            .ToListAsync();
    }

    /// <summary>
    /// 获取所有活跃的语言代码
    /// </summary>
    /// <returns>语言代码列表</returns>
    public async Task<List<string>> GetActiveLanguagesAsync()
    {
        return await Context.Set<Auto_LanguageFilterWords>()
            .Where(w => w.IsActive)
            .Select(w => w.Language)
            .Distinct()
            .ToListAsync();
    }
}